/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.etrs.formathlon.entity.formation;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import net.etrs.formathlon.entity.utils.ComparableEvenThoughUnpersisted;
import net.etrs.formathlon.persistance.utils.JpaRequestNames;

/**
 * Entité symbolisant le domaine général dans lequel s'inscrit une formation.
 * @author OPIF
 */
@Entity
@NamedQueries({
    @NamedQuery(name = JpaRequestNames.LISTE_DOMAINE_WITH_FORMATION,
    query = "select object(d) from Domaine d where d.archive = false "
    + "and d.listFormation is not empty")
})
public class Domaine extends ComparableEvenThoughUnpersisted<Domaine> {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String libelle;
    private String description;
    /**
     * Lorsque l'on supprime un domaine on supprime ses formations.
     */
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "domaine")
    private List<Formation> listFormation = new ArrayList<Formation>();
    private boolean archive = false;

    @Override
    public Long getId() {
        return id;
    }

    /**
     * Setter de l'id.
     * @param id 
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public String toString() {
        return String.format("Domaine id = %d, nom = %s, description = %s",
                id, libelle, description);
    }

    /**
     * @return the listFormation
     */
    public List<Formation> getListFormation() {
        return listFormation;
    }

    /**
     * @return the libelle
     */
    public String getLibelle() {
        return libelle;
    }

    /**
     * @param libelle the libelle to set
     */
    public void setLibelle(String libelle) {
        this.libelle = libelle;
    }

    /**
     * @param listFormation the listFormation to set
     */
    public void setListFormation(List<Formation> listFormation) {
        this.listFormation = listFormation;
    }

    /**
     * @return the archive
     */
    @Override
    public boolean isArchive() {
        return archive;
    }

    /**
     * @param archive the archive to set
     */
    @Override
    public void setArchive(boolean archive) {
        this.archive = archive;
    }
}
